package com.langxin.erp.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;


public class BaseAction {

	/**
	 * response
	 * @param response
	 * @param tip
	 */
	public void response(HttpServletResponse response, BindingResult errors){
		// 验证参数
    	try {
			if(errors.hasErrors()){
				List<FieldError> ls = errors.getFieldErrors(); 
				String msg = "";
			    for (int i = 0, j = ls.size(); i < j;) {  
			    	msg = ls.get(i).getDefaultMessage();
			    	break;
			    } 
			    response.getWriter().write("<script>alert('" + msg +"');window.history.go(-1);</script>");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
